package org.itboys.mobile.service.mongo.weixin;


import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.entity.ZhongBaoTag;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：众包_微信_标签_service
 */
@Service
public class ZhongBaoWeiXinTagService extends BaseMongoService<ZhongBaoTag> {



    @Resource(name = "mobileDs")
    private MongoDataSource mobileDataSource;
    @Override
    protected MongoDataSource getMongoDataSource() {
        return mobileDataSource;
    }

    @Override
    protected Class<ZhongBaoTag> getEntityClass() {
        return ZhongBaoTag.class;
    }

    //新增或修改标签
    public void saveTag(long memberId, long projectId,
                        String trade, Long provinceId, String provinceName, Long cityId, String cityName, String name1, String name2, String name3){
        Map<String,Object> param=new HashMap<String,Object>();
        param.put("isDeleted", SundayCommonConstants.NO);
        if(LongUtil.isNotZreo(projectId)){
            param.put("projectId",projectId);
        }
        if(LongUtil.isNotZreo(memberId)){
            param.put("memberId",memberId);
        }
        List<ZhongBaoTag> tags = super.list(param);
        ZhongBaoTag zhongBaoTag =new ZhongBaoTag( memberId,  projectId,  trade,  provinceId,  provinceName,  cityId,  cityName,  name1,  name2,  name3);
        if(ListUtil.isNotNull(tags)){
            super.updateExceptEmpty(tags.get(0).getId(),zhongBaoTag);
        }else{
            super.save(zhongBaoTag);

        }

    }

    /**
     * 查找标签
     * @param memberId
     * @param projectId
     * @return
     */
    public ZhongBaoTag getTag(long memberId, long projectId){
        Map<String,Object> param=new HashMap<String,Object>();
        param.put("isDeleted", SundayCommonConstants.NO);
        if(LongUtil.isNotZreo(projectId)){
            param.put("projectId",projectId);
        }
        if(LongUtil.isNotZreo(memberId)){
            param.put("memberId",memberId);
        }
        List<ZhongBaoTag> tags = super.list(param);
        if(ListUtil.isNotNull(tags)){
            return tags.get(0);
        }
        return new ZhongBaoTag();
    }
    /**
     *
     * @return
     */
    /**
     * 匹配标签
     * @param projectId
     * @return
     */
   public List<Long> match(Long projectId){
       return null;
   }

}
